import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.xml.sax.SAXException;

import javax.print.Doc;
import java.util.List;

/**
 * @author Administrator
 * @title: xmltest
 * @projectName JeePlus
 * @description: TODO
 * @date 2019/10/1818:13
 */

public class xmltest {
    private static Document dom;

    public static void main(String[] args) throws SAXException, DocumentException {
        String str = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
                " \n" +
                "<root>\n" +
                "\t<aaa id=\"ra\">\n" +
                "\t\t<bbb id=\"rab\"></bbb>\n" +
                "\t\t<ccc id=\"rac\">\n" +
                "\t\t\t<bbb id=\"racb\"></bbb>\n" +
                "\t\t</ccc>\n" +
                "\t</aaa>\n" +
                "\t<bbb id=\"rb\">\n" +
                "\t\t<ccc id=\"rbc\"></ccc>\n" +
                "\t</bbb>\n" +
                "</root>\n";
        String xpath = "//aaa/bbb/ab";
        //dom = new SAXReader().read("d:/xpath.xml");
        dom=DocumentHelper.parseText(str);
        @SuppressWarnings("unchecked")
        List<Element> selectNodes = dom.selectNodes(xpath);
        for (Element element : selectNodes) {
            System.out.println(element.attributeValue("id"));
        }
    }
}
